//app.js
require('./utils/batch.js')
const wxToast = require('./utils/wx-toast.js')
const http = require('./utils/http.js')
const toPromise = require('./utils/to-promise.js')
App({
    onLaunch: function () {
        wx.getSystemInfo({
            success: res => {
                this.window = { width: res.windowWidth, height: res.windowHeight }
            },
        })
    },
    http,
    toPromise,
    wxToast,
    storeId: 489,
    getPrevPage() {
        const ps = getCurrentPages()
        try {
            return ps[ps.length - 2]
        } catch (err) {
            return null
        }
    },
    getShareObj(title = "", params = {}, path = "") {
        const id = wx.getStorageSync('mid')
        if (!id) {
            return {}
        }
        const paramsArr = ["pmid=" + id]
        Object.keys(params).forEach(k => {
            paramsArr.push(k + "=" + params[k])
        })
        console.log(paramsArr, paramsArr, 'app1')
        const ps = getCurrentPages()
        console.log("/" + ps[ps.length - 1].route + "?" + paramsArr.join("&"), 'app2')
        return {
            title,
            path: "/" + ps[ps.length - 1].route + "?" + paramsArr.join("&")
        }
    },
    safeBack(url = '/pages/find/index') {
        const ps = getCurrentPages()
        if (ps.length > 1) {
            wx.navigateBack({

            })
        } else {
            wx.reLaunch({
                url,
            })
        }
    }
})
